package com.my.web.controller;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ConfigurationProperties(prefix = "person")//使用注解自动配置yml文件中person前缀的所有属性，需要为对应属性提供set方法
public class InitParamAutoConfigController {
    private String name;
    private int age;
    private String addr;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    @RequestMapping("/person")
    @ResponseBody
    public String method1() {
        //获取application.yml配置文件中的自定义配置参数
        return "name: " + name + " age:" + age + " addr:" + addr;
    }
}
